<template>
	<el-form ref="form" :model="form" label-width="200px">
		<el-form-item label="频道Key">
			<el-input v-model="form.key"></el-input>
		</el-form-item>
	
		<el-form-item label="频道名字">
			<el-input v-model="form.name"></el-input>
		</el-form-item>
		
		<el-form-item label="权重">
			<el-input v-model="form.weight"></el-input>
		</el-form-item>
		
		<el-form-item label="缩略图">
			<el-input v-model="form.thumbnail"></el-input>
		</el-form-item>
		
		<el-form-item>
			<el-button type="primary" @click="save()">保存</el-button>
	
		</el-form-item>
	</el-form>
</template>

<script>
	import axios from  'axios';
	// import http from  '@/utils/request.js'
	export default{
		name:'ChannelEdit',
		props:[
			"id"
		],
		data(){
			return {
				form:{
					key:'',
					name:'',
					weight:'',
					thumbnail:'',
				}
			}
		},
		methods:{
			// save(){
			// 	//
			// 	let urlSeachParames = new URLSearchParams();
			// 	urlSeachParames.append("key",this.form.key)
			// 	urlSeachParames.append("name",this.form.name)
			// 	urlSeachParames.append("weight",this.form.weight)
			// 	urlSeachParames.append("thumbnail",this.form.thumbnail)
				
			// 	let url = '';
			// 	if(this.id){
			// 		urlSeachParames.append("id",this.form.id)
			// 		url = '/api/channel?_type=update';
			// 	}else{
			// 		url ='/api/channel?_type=add'
			// 	}
				
			// 	axios.post(url,urlSeachParames).
			// 	then((ret)=>{
				
			// 		if(ret.status == 200){ //网络请求是通的，axios的状态
			// 			let response = ret.data;//响应结果
			// 			let {code ,msg ,data} = response;
			// 			if(code == 200){
			// 				if(data){
			// 					alert("保存成功")
			// 					this.$emit("update")
			// 				}else{
			// 					alert("保存失败")
			// 				}
							
			// 			}else{
			// 				alert("出错了:"+msg)
			// 			}
			// 		}
					
			// 	})
			// },
			save(){
				let url = '';
				if(this.id){
					url = '/api/channel?_type=update';
				}else{
					url ='/api/channel?_type=add'
				}
			
				this.$http.post(url,(data)=>{
					if(data){
						alert("保存成功")
						this.$emit("update")
					}else{
						alert("保存失败")
					}
				},this.form)
			},
			queryById(){
				let url = '/api/channel';
				this.$http.get(url,(data)=>{
					this.form = data;
				},{
					id:this.id,
					_type:'queryById'
				})
				
				
				// axios.get('/api/channel?_type=queryById&id='+this.id).
				// then((ret)=>{
				// 	if(ret.status == 200){ //网络请求是通的，axios的状态
				// 		let response = ret.data;//响应结果
				// 		let {code ,msg ,data} = response;
				// 		if(code == 200){
				// 			this.form = data;
							
				// 		}else{
				// 			alert("出错了:"+msg)
				// 		}
				// 	}
					
				// })
			}
		},
		created(){
			if(this.id){
				this.queryById();
			}
		}
	}
</script>

<style>
</style>
